/*
 * @Copyright: Citylife 2021
 * @Author: shaokui.gu
 * @Date: 2021-02-21 12:08:24
 * @Description: 
 */
import 'dart:developer';

import 'package:dio/dio.dart';

/// 跳过不处理
const int SKIP_STATUS_CODE = -19999;

/// 重新发起请求
const int RETRY_STATUS_CODE = -29999;

class NetworkResponseInterceptor extends Interceptor {
  @override
  void onResponse(Response response, ResponseInterceptorHandler handler) {
    // TODO: implement onResponse
    /// TODO: 处理Response
    switch (response.statusCode) {
      case 200:
        {
          log("http 请求成功拦截");

          /// TODO: returnCode 业务返回的code， 根据需求修改
          int returnCode = response.statusCode;
          switch (returnCode) {
            case 401:
              {
                /// 无权限做处理
                /// 告诉后续逻辑不要处理了，这里已经处理，直接跳过
                response.statusCode = SKIP_STATUS_CODE;
                break;
              }
            default:
              break;
          }
        }
        break;
      default:
        {
          log("http 请求异常拦截");

          /// TODO: 根据需求对特殊code进行处理

        }
    }
    super.onResponse(response, handler);
  }
}
